from configs import app_config
from agent_app import AgentApp


def init_app(app: AgentApp):
    # register blueprint routers

    from flask_cors import CORS  # type: ignore

    from controllers.console import bp as console_app_bp
    from controllers.mini_app import bp as mini_app_bp
    from controllers.robot import bp as robot_bp
    from controllers.files import bp as files_bp
    # from controllers.inner_api import bp as inner_api_bp
    # from controllers.service_api import bp as service_api_bp
    # from controllers.web import bp as web_bp
    # from controllers.mouse_api import bp as mouse_api_bp

    CORS(
        mini_app_bp,
        allow_headers=["Content-Type", "Authorization", "X-App-Code"],
        methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
    )
    app.register_blueprint(mini_app_bp)

    # CORS(
    #     web_bp,
    #     resources={r"/*": {"origins": app_config.WEB_API_CORS_ALLOW_ORIGINS}},
    #     supports_credentials=True,
    #     allow_headers=["Content-Type", "Authorization", "X-App-Code"],
    #     methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
    #     expose_headers=["X-Version", "X-Env"],
    # )

    # app.register_blueprint(web_bp)

    CORS(
        console_app_bp,
        resources={r"/*": {"origins": app_config.CONSOLE_CORS_ALLOW_ORIGINS}},
        supports_credentials=True,
        allow_headers=["Content-Type", "Authorization"],
        methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
        expose_headers=["X-Version", "X-Env"],
    )

    app.register_blueprint(console_app_bp)

    CORS(files_bp, allow_headers=["Content-Type"], methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"])
    app.register_blueprint(files_bp)

    # app.register_blueprint(inner_api_bp)

    ## 
    CORS(
        robot_bp,
        allow_headers=["Content-Type", "Authorization", "X-App-Code","X-Timestamp","X-Signature"],
        methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
    )
    app.register_blueprint(robot_bp)
